package com.ruoyi.project.meal.controller;

import java.util.List;

import com.ruoyi.project.meal.domain.MealMilkList;
import com.ruoyi.project.meal.service.IMealMilkListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 牛奶明细Controller
 * 
 * @author ruoyi
 * @date 2024-03-14
 */
@Controller
@RequestMapping("/meal/milkList")
public class MealMilkListController extends BaseController
{
    private String prefix = "meal/milkList";

    @Autowired
    private IMealMilkListService mealMilkListService;

    @RequiresPermissions("meal:milk:view")
    @GetMapping()
    public String milk()
    {
        return prefix + "/milk";
    }

    /**
     * 查询牛奶明细列表
     */
    @RequiresPermissions("meal:milk:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MealMilkList mealMilkList)
    {
        startPage();
        List<MealMilkList> list = mealMilkListService.selectMealMilkListList(mealMilkList);
        return getDataTable(list);
    }

    /**
     * 导出牛奶明细列表
     */
    @RequiresPermissions("meal:milk:export")
    @Log(title = "牛奶明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MealMilkList mealMilkList)
    {
        List<MealMilkList> list = mealMilkListService.selectMealMilkListList(mealMilkList);
        ExcelUtil<MealMilkList> util = new ExcelUtil<MealMilkList>(MealMilkList.class);
        return util.exportExcel(list, "milk");
    }

    /**
     * 新增牛奶明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存牛奶明细
     */
    @RequiresPermissions("meal:milk:add")
    @Log(title = "牛奶明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MealMilkList mealMilkList)
    {
        return toAjax(mealMilkListService.insertMealMilkList(mealMilkList));
    }

    /**
     * 修改牛奶明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        MealMilkList mealMilkList = mealMilkListService.selectMealMilkListById(id);
        mmap.put("mealMilkList", mealMilkList);
        return prefix + "/edit";
    }

    /**
     * 修改保存牛奶明细
     */
    @RequiresPermissions("meal:milk:edit")
    @Log(title = "牛奶明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MealMilkList mealMilkList)
    {
        return toAjax(mealMilkListService.updateMealMilkList(mealMilkList));
    }

    /**
     * 删除牛奶明细
     */
    @RequiresPermissions("meal:milk:remove")
    @Log(title = "牛奶明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mealMilkListService.deleteMealMilkListByIds(ids));
    }
}
